﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;
using System.IO;
using System.Dynamic;
using FluorineFx.Json;

namespace lxwmvc
{
    /// <summary>
    /// 注册db
    /// </summary>
    public static class core_regdb
    {
        /// <summary>
        /// 判断数据库中用户是否存在。注意外部用户和内部用户的问题
        /// </summary>
        /// <param name="sjh"></param>
        /// <returns></returns>
        public static bool checkUserByMobile(string sjh)
        {
            return supermodel
                .create("sysuser")
                .select("count(1)")
                .where("MOBIL_NO='" + sjh + "' and NOT_LOGIN='1' ")
                .one<int>() > 0;  
        }

        /// <summary>
        /// 获取用户ID
        /// </summary>
        /// <param name="sjh"></param>
        /// <returns></returns>
        public static int getUserByMobile(string sjh)
        {
            return supermodel
                .create("sysuser")
                .select("user_id")
                .where("MOBIL_NO='" + sjh + "' and NOT_LOGIN='1' ")
                .one<int>();
        }

        /// <summary>
        /// 判断邀请码是否存在
        /// </summary>
        /// <param name="yqm"></param>
        /// <returns></returns>
        public static bool checkYaoQingMaShiFouCunZai(string yqm)
        {
            return supermodel
                .create("sysuser")
                .select("COUNT(1)")
                .where("USER_ID='" + yqm.toint32(-1) + "' and NOT_LOGIN='1' ")
                .one<int>() > 0;
        }

        
        /// <summary>
        /// 防止重复登录
        /// </summary>
        /// <param name="pb"></param>
        /// <param name="user_id"></param>
        public static void checkFangZhiCHongFuDengLu(pagebase pb, string user_id)
        {
            var fangzhiduoyonghudenglu = cryptohelper.encode((DateTime.Now + user_id));
            pb.Session["g_user_id_more"] = fangzhiduoyonghudenglu;

            supermodel
                   .create("sysuser_kuozhan")
                   .set("fangzhiduoyonghudenglu", fangzhiduoyonghudenglu)
                   .where("user_id='" + user_id + "'")
                   .update();
        }
    }
}